﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BanHangCshap.Class
{
    class ChucNangNhomND:Database
    {
        #region ***** Fields & Properties *****
        private int _manhomnd;
        public int manhomnd
        {
            get
            {
                return _manhomnd;
            }
            set
            {
                _manhomnd = value;
            }
        }
        private string _macn;
        public string macn
        {
            get
            {
                return _macn;
            }
            set
            {
                _macn = value;
            }
        }
        #endregion

        #region ***** Init Methods *****
        public ChucNangNhomND()
        {
        }
        public ChucNangNhomND(int manhomnd)
        {
            this.manhomnd = manhomnd;
        }
        public ChucNangNhomND(int manhomnd, string macn)
        {
            this.manhomnd = manhomnd;
            this.macn = macn;
        }
        #endregion
        public Boolean themChucNangNhomND()
        {
            string sql = "insert into ChucNangNhomND(macn,manhomnd) values ('" + macn + "', '" + manhomnd + "')";
            return executeQuery(sql);
        }
        public Boolean xoaChucNangNhomND(string macn, int manhomnd)
        {
            string sql = "delete ChucNangNhomND where macn = '" + macn + "' and manhomnd = " + manhomnd + "";
            return executeQuery(sql);
        }
        public DataTable layDSChucNangNhomND()
        {
            string sql = "select a.manhomcn,tennhomcn,a.macn,tencn from ChucNang a left join NhomChucNang b on a.manhomcn = b.manhomcn left join ChucNangNhomND c on a.macn = c.macn ";
            return getDataTable(sql);
        }
        public Boolean xoaCNCuaNhomND(int manhomnd)
        {
            string sql = "delete ChucNangNhomND where manhomnd = " + manhomnd + " ";
            return executeQuery(sql);
        }
        public DataTable layDSQuyenCuaNhomND(int manhomnd)
        {
            string sql = "select a.manhomcn,tennhomcn,a.macn,tencn from ChucNang a,NhomChucNang b,ChucNangNhomND c  where a.manhomcn = b.manhomcn and  a.macn = c.macn and c.manhomnd = " + manhomnd + " order by a.manhomcn ";
            return getDataTable(sql);
        }

    }
}
